<template>
  <div class="app-container">
    <!-- 搜索行 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="88px"
    >
      <el-form-item
        :label="`${$schoolName ? $schoolName : '学校'}名称`"
        prop="schoolName"
      >
        <el-input
          v-input-restrict
          v-model="queryParams.schoolName"
          :placeholder="`请输入${$schoolName ? $schoolName : '学校'}名称`"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="平时分状态" prop="levelName">
        <el-select
          filterable
          v-model="queryParams.openUsualScore"
          placeholder=""
          clearable
        >
          <el-option label="开" value="1" />
          <el-option label="关" value="0" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          v-preventReClick
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          v-preventReClick
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 表格 -->
    <el-table v-loading="loading" :data="postList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        :label="`${$schoolName ? $schoolName : '学校'}编号`"
        align="center"
        prop="schoolNum"
      />
      <el-table-column
        width="100"
        :label="`${$schoolName ? $schoolName : '学校'}logo`"
        align="center"
        prop="schoolPic"
      >
        <template slot-scope="scope">
          <el-image
            style="width: 80px; height: auto"
            :src="scope.row.schoolPic"
            :preview-src-list="[scope.row.schoolPic]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column
        width="400"
        :label="`${$schoolName ? $schoolName : '学校'}名称`"
        align="center"
        prop="schoolName"
      />

      <el-table-column
        label="最后操作时间"
        align="center"
        prop="createTime"
        min-width="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime).slice(0, 10) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="平时分开启状态" align="center" prop="status">
        <template slot-scope="scope">
          <!-- 开关 1是开 0是关-->

          <el-switch
            :active-value="1"
            :inactive-value="0"
            v-model="scope.row.openUsualScore"
            active-color="#13ce66"
            inactive-color="#ff4949"
            @change="handleStatusChange($event, scope.row)"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
  
  <script>
import { listPost_school } from "@/api/school/list";
import { updatePost_school } from "@/api/schoolOrganization/schoolInfo";
export default {
  name: "Post",
  dicts: ["sys_normal_disable"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // level
      level: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        schoolName: undefined,
        openUsualScore: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async handleStatusChange(e, row) {
      let data = { ...row };
      data.openUsualScore = e;
      await updatePost_school(data);
      this.$modal.msgSuccess("操作成功");
      row.openUsualScore = e;
    },
    // 停用 启用按钮
    handleSwitch(row) {
      let txt =
        row.status == 0
          ? `确定停用【${row.schoolName}】学校吗?停用后该学校所有的关联账号不可使用！`
          : `确认启用【${row.schoolName}】学校吗?启用后该学校可使用`;
      this.$confirm(txt, `${row.status == 0 ? "停用确认" : "启用确认"}`, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = JSON.parse(JSON.stringify(row));
          data.status = row.status == 0 ? 1 : 0;
          updatePost_school(data).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        })
        .catch(() => {});
    },

    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listPost_school(this.queryParams).then((response) => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
  <style scoped lang="scss">
::v-deep .el-menu-item:hover {
  border-bottom: 1px solid #e6e6e6 !important;
}
::v-deep .el-menu--horizontal > .el-menu-item.is-active:hover {
  border-bottom: 2px solid #11a983 !important;
}
.startTime_add {
  width: 160px;
}
.level_add {
  width: 354px;
}
</style>
  